// Copyright [2020] <unknown>
#include <bits/stdc++.h>
using namespace std;
// #define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
#define dbg(x...)                             \
    {                                         \
        cerr << "\033[32;1m" << #x << " -> "; \
        err(x);                               \
    }
void err() { cerr << "\033[39;0m" << endl; }
template <typename T, typename... A>
void err(T a, A... x) {
    cerr << a << ' ';
    err(x...);
}
#else
#define dbg(...)
#endif

#define sz(x) ((int)x.size())

typedef long long LL;

int t, n, q;

const int N = 124, M = 2e5 + 50;

int cur;
int pivot[N], rp[N];

struct Edge {
    int u, v;
    LL w, a;
} dat[M];

bitset<N> a[M];
LL ans[N];

bitset<N> A[N];

int m;
LL w[N];
void add(bitset<N> a, LL v) {
    for (int i = a._Find_first(); i<N; i=a._Find_next(i)) {
        if (!w[i]) {
            A[i] = a;
            w[i] = v;
            return;
        } else if (w[i] < v) {
            swap(w[i], v);
            swap(A[i], a);
        }
        a ^= A[i];
        // i = a._Find_first();
    }
}

int main(int argc, char const *argv[]) {
    // bitset<10> t;
    // t.reset();
    // cout << t._Find_first() << endl;
    // return 0;
    // code
    scanf("%d%d", &n, &q);
    m = n + 60;
    for (int i = 0; i < q; ++i) {
        a[i].reset();

        scanf("%d%d%lld%lld", &dat[i].u, &dat[i].v, &dat[i].w, &dat[i].a);
    }

    for (int i = 0; i < q; ++i) {
        for (int j = 0; j < 60; ++j) {
            if ((dat[i].w >> j) & 1)
                a[i][j] = 1;
        }

        a[i][dat[i].u - 1 + 60] = 1;
        a[i][dat[i].v - 1 + 60] = 1;
    }

    for (int i = 0; i < q; ++i) {
        
        add(a[i], dat[i].a);
        LL ans = 0;
        for (int i = 0; i < m; ++i)
            ans += w[i];
        printf("%lld\n", ans);
    }

    return 0;
}
